package com.lightsaber.trade.as.common.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AbstractUITag;
import org.springside.modules.utils.spring.SpringContextHolder;

import com.lightsaber.trade.as.service.param.ProductTypeManager;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * Convert code to label
 * 
 * @author LiuJian
 * 
 */
public class ProductTypeDropdownTag extends AbstractUITag {

    private static final long serialVersionUID = 1L;

    private String bean;

    @Override
    public Component getBean(final ValueStack valueStack, final HttpServletRequest request,
            final HttpServletResponse respose) {
        return new ProductTypeDropdown(valueStack, request, respose);
    }

    @Override
    protected void populateParams() {
        super.populateParams();

        ProductTypeDropdown productTypeDropdown = (ProductTypeDropdown) component;

        ProductTypeManager productTypeManager = SpringContextHolder
                .getBean(ProductTypeManager.class);
        String[] categories = productTypeManager.findAllCategoryDistinct();

        productTypeDropdown.setCategories(categories);
        productTypeDropdown.setBean(bean);

    }

    public void setBean(String bean) {
        this.bean = bean;
    }

}
